package br.unifor.cct.mia.runner;

import java.util.ArrayList;
import java.util.Iterator;

import br.unifor.cct.mia.coevolution.CoevolutionaryDomain;
import br.unifor.cct.mia.coevolution.memory.SharedMemory;
import br.unifor.cct.mia.dataenhancement.Database;
import br.unifor.cct.mia.dataenhancement.Structure;
import br.unifor.cct.mia.evaluate.Evaluate;
import br.unifor.cct.mia.evolutionary.Specie;
import br.unifor.cct.mia.ga.Ga;
import br.unifor.cct.mia.ga.coevolutionary.CoevGaIS;
import br.unifor.cct.mia.pso.PSO;
import br.unifor.cct.mia.pso.coevolutionary.CoevPSOFS;
import br.unifor.cct.mia.util.LoadFile;

public class PSOCoevolucionary {

	public static void main(String[] args) {
		try {
			new PSOCoevolucionary().createDomain();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private Integer learnerType =  Evaluate.J48;
	
	private void createDomain() throws Exception {
		
		final String DATASET_STRUCTURE = "E:\\Pedro\\Convertidas\\zoo_struc.txt";
		final String DATASET_DATA = "E:\\Pedro\\Convertidas\\zoo_data.txt";
		
		final CoevolutionaryDomain domain = new CoevolutionaryDomain(CoevolutionaryDomain.MEMORY,learnerType);
		final ArrayList<Specie> species =  new ArrayList<Specie>();

		final Structure st = LoadFile.loadStructure(DATASET_STRUCTURE);
    	final Database db = LoadFile.loadDatabase(DATASET_DATA);
    	
    	Ga gaCoev = new CoevGaIS(db,st,domain,null);
    	gaCoev.setLearnerType(learnerType);
    	gaCoev.setPOPSIZE( 10 );
    	gaCoev.setMAXGENS( 20 );
    	gaCoev.setPMUTATION( 0.05 );
    	gaCoev.setPXOVER( 0.6 );			                    
    	species.add( gaCoev );	
		
		PSO psoCoev = new CoevPSOFS(db,st,domain,null);
		psoCoev.setPopSize(10);
		psoCoev.setExecSize(20);
		species.add( psoCoev );	
    	
		domain.setSpecies(species);
		domain.setOptions(null);		
		domain.start();	
		
		SharedMemory memory = domain.getBest();	
		System.out.println("Fitness: "+memory.getFitness()+"\n\n");
		
		ArrayList elements = memory.getElements();
		Iterator iter = elements.iterator();
		while(iter.hasNext()) {
			System.out.println(iter.next());
		}
	}	
	
}
